package uia.alumni.profile;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import uia.alumni.data.User;

/**
 * This is a small manager Class to Simplify common tasks and to
 * keep code at one place.
 * 
 * @author Simon Zimmermann. 
 */
public class ProfileManager {

    private HttpServletRequest request;
    private EntityManager em;

    public ProfileManager(HttpServletRequest request, EntityManager em) {
        this.request = request;
        this.em = em;
    }

    /**
     * Find out if something is a unique Email. 
     * @param email
     * @return
     */
    public boolean isUniqueEmail(String email) {
        Query q = em.createNamedQuery("User.findByEmail");
        q.setParameter("email", email);
        List<User> l = (List<User>) q.getResultList();
        if (l != null && !l.isEmpty()) {
            return false;
        }
        return true;
    }
}
